//import java.util.*;
//
//class Bonus {
//    public int getMost(int[][] board) {
//        int n = board.length, m = board[0].length;
//        int[][] dp = new int[n+1][m+1];
//        for(int i = 1; i<=n; i++) {
//            for(int j = 1; j<=m; j++) {
//                dp[i][j] = Math.max(dp[i][j-1],dp[i-1][j]) + board[i-1][j-1];
//            }
//        }
//        return dp[n][m];
//    }
//}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int[] xx = {0, 0, 1, -1};
    static int[] yy = {1, -1, 0, 0};
    static List<int[]> list = new ArrayList<>();
    static int n, m;
    static int[][] board;
    static boolean[][] st;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        if(n == 0 && m ==0) {
            return;
        }
        board = new int[n][m];
        for(int i = 0; i<n;i++) {
            for(int j = 0; j<m;j++) {
                board[i][j] = scanner.nextInt();
            }
        }
        st = new boolean[n][m];
        st[0][0] = true;
        list.add(new int[]{0,0});
        dfs(0, 0);
    }

    public static void dfs(int a, int b) {
        if (a == n-1 && b == m-1) {
            for (int i = 0; i < list.size(); i++) {
                int[] t = list.get(i);
                System.out.println("(" + t[0] + "," + t[1] + ")");
            }
            return;
        }
        for(int i = 0; i<4; i++) {
            int x = a+xx[i];
            int y = b+yy[i];
            if(x>=0 && x<n && y>=0 && y<m && board[x][y] == 0 && !st[x][y]) {
                st[x][y] = true;
                list.add(new int[]{x,y});
                dfs(x,y);
                list.remove(list.size()-1);
            }
        }
    }
}
